import java.awt.Color;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.ButtonGroup;
import javax.swing.ButtonModel;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JRadioButton;
import javax.swing.JComboBox;
import javax.swing.JButton;
import javax.swing.JTextArea;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;


public class Interfazea extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JPanel contentPane;
	private final JTextField txtIzena = new JTextField();
	private JRadioButton rdbtnE;
	private JRadioButton rdbtnG;
	private JComboBox comboBox;
	private JTextArea textArea;
	private ButtonGroup grupoBotonesOpcion;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Interfazea frame = new Interfazea();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public Interfazea() {
		setTitle("Tituloa");
		// Edozer
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblSartuEzazuZenbaki = new JLabel("Izena:");
		lblSartuEzazuZenbaki.setBounds(12, 12, 55, 32);
		contentPane.add(lblSartuEzazuZenbaki);
		txtIzena.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				txtIzena.setBackground(new Color(255, 255, 255));
				textArea.setText("");
			}
		});
		txtIzena.setBounds(85, 11, 319, 33);
		contentPane.add(txtIzena);
		txtIzena.setColumns(10);
		
		rdbtnE = new JRadioButton("Emakumea");
		rdbtnE.setBounds(85, 52, 114, 23);
		contentPane.add(rdbtnE);
		
		rdbtnG = new JRadioButton("Gizona");
		rdbtnG.setBounds(85, 79, 74, 23);
		contentPane.add(rdbtnG);
		
		// crear relación lógica entre objetos JRadioButton
		grupoBotonesOpcion = new ButtonGroup();
		grupoBotonesOpcion.add( rdbtnE );
		grupoBotonesOpcion.add( rdbtnG );
		
		JLabel lblSexua = new JLabel("Sexua:");
		lblSexua.setBounds(12, 56, 70, 15);
		contentPane.add(lblSexua);
		
		comboBox = new JComboBox();
		comboBox.setBounds(128, 114, 92, 24);
		for(int i=1900; i<2000; i++ )
			comboBox.addItem(new Integer(i));
		contentPane.add(comboBox);
		
		JLabel lblJaiotzeUrtea = new JLabel("Jaiotze urtea:");
		lblJaiotzeUrtea.setBounds(12, 110, 98, 33);
		contentPane.add(lblJaiotzeUrtea);
		
		JButton btnDatuakBidali = new JButton("Datuak bidali");
		btnDatuakBidali.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
				if (txtIzena.getText().equals("")) {
					textArea.setText("Sartu zure izena");
					txtIzena.setBackground(new Color(255, 0, 0));
					
				} else {
				
					String sexua = "S";
					
					ButtonModel bm = grupoBotonesOpcion.getSelection();
					
					if (rdbtnE.getModel() == bm) sexua = rdbtnE.getText();
					else sexua = rdbtnG.getText();
					
					
					Integer urtea = (Integer)comboBox.getSelectedItem();
					textArea.setText("Zure datuak heldu dira:\nIzena: " +txtIzena.getText()+ "\nSexua: "+sexua + "\nJaiotze urtea: " + urtea);
						
				}
				// Hemen datuak bidali
			}
		});
		btnDatuakBidali.setBounds(269, 114, 139, 25);
		contentPane.add(btnDatuakBidali);
		
		textArea = new JTextArea();
		textArea.setBounds(12, 167, 398, 77);
		contentPane.add(textArea);
	}
}